-
Notifications
You must be signed in to change notification settings - Fork 65
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Accept selection state from mutating select elements #59
base: master
Are you sure you want to change the base?
Conversation
Did you run the tests after making this change? |
@kristoferjoseph Looks as if I omitted the tests, unfortunately. Tried now and one test is failing. |
@kristoferjoseph Specifically, the test 'input values get copied' fails. Why is it that the |
OK.
SELECT may be a special case.
Do me a favor and add a test for the SELECT behavior you are expecting.
Might need your add one more if else clause.
✌
…On Sun, Jan 8, 2017, 10:55 AM Arve Knudsen ***@***.***> wrote:
@kristoferjoseph <https://github.com/kristoferjoseph> Looks as if I
omitted the tests, unfortunately. Tried now and one test is failing.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#59 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AAEqFL_QBzJG8fH1sw1DYNOseFuqOhcvks5rQTEYgaJpZM4LX7XC>
.
|
@kristoferjoseph The test in question doesn't really make sense to me, I think we better resolve how this is supposed to work before we go any further. To me, it seems that the test should assert that |
It makes sure that if _no_ value is on the _new_ element that the _old_
value is copied over.
Otherwise every DOM update would lose the existing value in your input.
…On Sun, Jan 8, 2017, 11:02 AM Arve Knudsen ***@***.***> wrote:
@kristoferjoseph <https://github.com/kristoferjoseph> The test in
question doesn't really make sense to me, I think we better resolve how
this is supposed to work before we go any further. To me, it seems that the
test should assert that newEl.value gets copied to el. Is this wrong?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#59 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AAEqFIPMgQo-Pui4eKRx3N9vDvMb-o3hks5rQTK-gaJpZM4LX7XC>
.
|
@kristoferjoseph It also ensures that new values don't get copied over however, I just checked. |
What if you want to erase an input's value when you re-render, how do you control this if yo-yo ignores this change? Doesn't seem to make sense to me. |
The pattern that would make sense to me is to record when an input's |
@kristoferjoseph I see now that yo-yo checks if the mutating element has |
The thinking behind this is that the input element is for user input. It
errors on the side of the input value being changed by the user.
I agree you could add tests and a case for when the new input has a value
already.
…On Sun, Jan 8, 2017, 11:14 AM Arve Knudsen ***@***.***> wrote:
The pattern that would make sense to me is to record when an input's value
changes and render this into DOM updates.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#59 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AAEqFC1pHocR9tYzeB7-k1VSMegeBR2rks5rQTWFgaJpZM4LX7XC>
.
|
a05af8a
to
1d93c20
Compare
@kristoferjoseph I rewrote the original test slightly and added a new one, asserting that new input values get copied if they are actually set. |
However, I have to deal with the select case. |
@kristoferjoseph I tested one more thing, the case where you clear the Nevermind: This actually works, not sure what I did wrong before. |
1d93c20
to
d1f4315
Compare
I've reverted to the original behaviour and added a test for the clearing of input value case. Will have to add handling of selects, as per the bug I experienced. |
@kristoferjoseph Does it ever make sense to keep the Even if the select has no elements, the selectedIndex will be -1 and in that case I don't see any point in maintaining it as the mutated select will lose all its children anyway. |
I've made the change in my branch now to not change the selection state of select elements. I don't see any case where it makes sense, although I could be missing something. |
8b800f9
to
212488c
Compare
212488c
to
79c77a0
Compare
@aknuds1 as for keeping the selected index. Imagine a scenario where you have set the select index then update something else in the same scope. You want to make sure the index is maintained during an unrelated update. |
@kristoferjoseph How would you formulate this into a test case? I can't see any way that |
I think it's way safer to set all properties you need on the mutating element, rather than to expect yo-yo to maintain them. |
@kristoferjoseph That doesn't show how to test this for |
Ah, sorry, was actually replying to one of your earlier questions. I will make a select test as well. Was hoping this patch might fix some of the other issues you were seeing. |
@kristoferjoseph Is it necessarily a great idea to implement this sort of intelligence in nanomorph? I suspect it violates the principle of least surprise, at least I was surprised to find that yo-yo tries to preserve old values as opposed to copying directly from the incoming/mutating element. Does morphdom function in this way too? |
I would say that it is more surprising when an input value is lost when a
parent node is updated.
Imagine the use case. You type something into an input then do something
unrelated, like open a drop-down and your input value is lost.
Does that make it more clear?
…On Tue, Jan 10, 2017, 6:30 AM Arve Knudsen ***@***.***> wrote:
@kristoferjoseph <https://github.com/kristoferjoseph> Is it necessarily a
great idea to implement this sort of intelligence into nanomorph? I suspect
it violates the principle of least surprise, at least I was surprised to
find that yo-yo tries to preserve old values as opposed to copying directly
from the incoming/mutating element.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#59 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AAEqFOqY5cE9zlLQkuAHBXA7JkDs26Ouks5rQ5XrgaJpZM4LX7XC>
.
|
@kristoferjoseph Yeah it makes it more clear, but I'm just not so sure a morphing library should do this. It sounds like a decision to be made on top of the morphing, i.e. it might be undesirable to the user of the morphing library. The value preservation algorithm certainly is imperfect as it stands, as my scenario with the select elements shows. I'm discussing with @yoshuawuyts however, and he explained why it's useful in the Choo context. I think it really depends on higher level concerns (such as Choo), so I'm just not so sure the behaviour should be hardcoded into nanomorph. I don't know how it works in morphdom, but I suspect it doesn't have this sort of intelligence built in, since yo-yo is implementing it on top of it. I suspect it would be better handled by a module around nanomorph. |
@kristoferjoseph come to IRC 🕥 ✨ 🎉 |
It's good we're having this discussion though, I wasn't aware of the issues you can run into without preserving values in the Choo context until @yoshuawuyts explained it to me. |
Happy to hear it is becoming more clear. This is one concept that is
definitely different in use vs theory. Which makes it a contentious issue.
I'm terrible at IRC or I'd be there already 😬
…On Tue, Jan 10, 2017, 7:17 AM Arve Knudsen ***@***.***> wrote:
It's good we're having this discussion though, I wasn't aware of the
issues you can run into without preserving values until @yoshuawuyts
<https://github.com/yoshuawuyts> explained it to me.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#59 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AAEqFG9awZK1eS94ip5X5RhmguGn6Yc3ks5rQ6DtgaJpZM4LX7XC>
.
|
@kristoferjoseph http://irccloud.com/ and then join freenode and #choo :D - I believe in you |
Don't change incoming selection state when mutating
select
elements.Fixes #58